/*
 * GPSMapView.java
 */
package gpsmap;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
//import org.jdesktop.swingx.JXMapViewer;
import javax.swing.JOptionPane;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import weather_service.*;





/**
 *
 * The application's main frame.
 * @author Pooyan Mobtahej
 */
public class GPSMapView extends FrameView implements Runnable {
    boolean mouseSlector = false;
    final static RouteDrawer routeDrawer = new RouteDrawer();
     Thread rdThread = new Thread(routeDrawer);
     MP3Player p = new MP3Player("voice//Allvoice.mp3");
      Thread mp3Thread = new Thread(p);
    WaypointPainter wpPainter = new WaypointPainter();
//     Thread cpThread = new Thread();

    public GPSMapView(SingleFrameApplication app) {
        super(app);

        super.getFrame().setTitle("Extreme GPS");
        initComponents();
        try{
            TestWeatherGateway  twg = new TestWeatherGateway();
            twg.weatherInfo();
        jLabel3.setText("tempreture : " + twg.iconNo);

        String path = "icons//" + twg.iconNo +".png";
        ImageIcon icon = new ImageIcon(path);

        lbl_Icon.setIcon(icon);
        lbl_temperature1.setText("Temperature: " + Integer.toString(twg.temperature)+ "  degrees");
        lbl_humidity.setText("Humidity: " + twg.humidity);
        lbl_description.setText("Weather Condition: " + twg.description);
        lbl_location.setText("Location: " + twg.location);

        }catch(Exception e){

            JOptionPane.showMessageDialog(null, " No Connection to the internet ", "No service", 1);

        }
        
        
        jLabel3.setText(Double.toString(routeDrawer.getStartPoint().getLatitude()));
         jLabel4.setText(Double.toString(routeDrawer.getStartPoint().getLongitude()));
         
            distanceLabel.setText("Unknown");
        
         jLabel1.setText("Distance: ");

//        String rr = twg.temperature + "";
//        jLabel3.setText(rr);

        btn_Navigate.setText("Start Navigation");
//        btn_Clear.setText("Clear");

        btn_Navigate.setText("Start Navigation");
//        btn_Clear.setText("Clear");
        btn_voice.setText("Voice help");


        buttonGroup1.add(jRadioButton1);
        buttonGroup1.add(jRadioButton2);
        jRadioButton1.setSelected(true);


        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
//        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
//        messageTimer = new Timer(messageTimeout, new ActionListener() {
//
//            public void actionPerformed(ActionEvent e) {
//                statusMessageLabel.setText("");
//            }
//        });
//        messageTimer.setRepeats(false);
//        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
//        for (int i = 0; i < busyIcons.length; i++) {
//            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
//        }
//        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
//
//            public void actionPerformed(ActionEvent e) {
//                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
//                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
//            }
//        });
//        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
//        statusAnimationLabel.setIcon(idleIcon);
//		progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
//        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

//            public void propertyChange(java.beans.PropertyChangeEvent evt) {
//                String propertyName = evt.getPropertyName();
//                if ("started".equals(propertyName)) {
//                    if (!busyIconTimer.isRunning()) {
//                        statusAnimationLabel.setIcon(busyIcons[0]);
//                        busyIconIndex = 0;
//                        busyIconTimer.start();
//                    }
//					progressBar.setVisible(true);
//					progressBar.setIndeterminate(true);
//                } else if ("done".equals(propertyName)) {
//                    busyIconTimer.stop();
//                    statusAnimationLabel.setIcon(idleIcon);
////					progressBar.setVisible(false);
////					progressBar.setValue(0);
//                } else if ("message".equals(propertyName)) {
//                    String text = (String) (evt.getNewValue());
//                    statusMessageLabel.setText((text == null) ? "" : text);
//                    messageTimer.restart();
//                } else if ("progress".equals(propertyName)) {
//                    int value = (Integer) (evt.getNewValue());
////					progressBar.setVisible(true);
////					progressBar.setIndeterminate(false);
////					progressBar.setValue(value);
//                }
//            }
//        });
//        jXMapKit1.setAddressLocation(new GeoPosition(57.706806, 11.937413));

        jXMapKit1.setCenterPosition(new GeoPosition(57.706806, 11.937413));
        jXMapKit1.setZoom(3);
//        cpThread.start();


//        MP3Player player = new MP3Player("voice//1.mp3");
//         player.play();
        mp3Thread.start();

    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = GPSMapApp.getApplication().getMainFrame();
            aboutBox = new GPSMapAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        GPSMapApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jXMapKit1 = new org.jdesktop.swingx.JXMapKit();
        jPanel1 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        latitude_Lable = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        latitude_Lable1 = new javax.swing.JLabel();
        btn_Navigate = new javax.swing.JButton();
        lbl_Icon = new javax.swing.JLabel();
        lbl_temperature = new javax.swing.JLabel();
        lbl_temperature1 = new javax.swing.JLabel();
        lbl_humidity = new javax.swing.JLabel();
        lbl_location = new javax.swing.JLabel();
        lbl_description = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        btn_Close = new javax.swing.JButton();
        distanceLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        btn_voice = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        buttonGroup1 = new javax.swing.ButtonGroup();

        mainPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        mainPanel.setName("mainPanel"); // NOI18N

        jXMapKit1.setDefaultProvider(org.jdesktop.swingx.JXMapKit.DefaultProviders.OpenStreetMaps);
        jXMapKit1.setName("jXMapKit1"); // NOI18N
        jXMapKit1.getMainMap().addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jXMapKit1MouseClicked(evt);
            }
        });

        jPanel1.setName("jPanel1"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Destination", "Restaurant Åran", "BackaTheatre", "Science Park", "Jupiter entrance", "Ester Mosessons café", "Navigating by Mouse" }));
        jComboBox1.setName("jComboBox1"); // NOI18N
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(GPSMapView.class);
        latitude_Lable.setText(resourceMap.getString("latitude_Lable.text")); // NOI18N
        latitude_Lable.setToolTipText(resourceMap.getString("latitude_Lable.toolTipText")); // NOI18N
        latitude_Lable.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        latitude_Lable.setName("latitude_Lable"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jRadioButton1.setText(resourceMap.getString("jRadioButton1.text")); // NOI18N
        jRadioButton1.setName("jRadioButton1"); // NOI18N

        jRadioButton2.setText(resourceMap.getString("jRadioButton2.text")); // NOI18N
        jRadioButton2.setName("jRadioButton2"); // NOI18N

        latitude_Lable1.setText(resourceMap.getString("latitude_Lable1.text")); // NOI18N
        latitude_Lable1.setToolTipText(resourceMap.getString("latitude_Lable1.toolTipText")); // NOI18N
        latitude_Lable1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        latitude_Lable1.setName("latitude_Lable1"); // NOI18N

        btn_Navigate.setText(resourceMap.getString("btn_Navigate.text")); // NOI18N
        btn_Navigate.setActionCommand(resourceMap.getString("btn_Navigate.actionCommand")); // NOI18N
        btn_Navigate.setName("btn_Navigate"); // NOI18N
        btn_Navigate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_NavigateActionPerformed(evt);
            }
        });

        lbl_Icon.setText(resourceMap.getString("lbl_Icon.text")); // NOI18N
        lbl_Icon.setName("lbl_Icon"); // NOI18N

        lbl_temperature.setText(resourceMap.getString("lbl_temperature.text")); // NOI18N
        lbl_temperature.setName("lbl_temperature"); // NOI18N

        lbl_temperature1.setText(resourceMap.getString("lbl_temperature1.text")); // NOI18N
        lbl_temperature1.setName("lbl_temperature1"); // NOI18N

        lbl_humidity.setText(resourceMap.getString("lbl_humidity.text")); // NOI18N
        lbl_humidity.setName("lbl_humidity"); // NOI18N

        lbl_location.setText(resourceMap.getString("lbl_location.text")); // NOI18N
        lbl_location.setName("lbl_location"); // NOI18N

        lbl_description.setText(resourceMap.getString("lbl_description.text")); // NOI18N
        lbl_description.setName("lbl_description"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        btn_Close.setText(resourceMap.getString("btn_Close.text")); // NOI18N
        btn_Close.setName("btn_Close"); // NOI18N
        btn_Close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CloseActionPerformed(evt);
            }
        });

        distanceLabel.setText(resourceMap.getString("distanceLabel.text")); // NOI18N
        distanceLabel.setName("distanceLabel"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        btn_voice.setText(resourceMap.getString("btn_voice.text")); // NOI18N
        btn_voice.setName("btn_voice"); // NOI18N
        btn_voice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_voiceActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_temperature, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jRadioButton1)
                                .addGap(34, 34, 34)
                                .addComponent(jRadioButton2))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(latitude_Lable, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel3))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_humidity)
                            .addComponent(lbl_location)
                            .addComponent(lbl_description)
                            .addComponent(lbl_temperature1)
                            .addComponent(jLabel5)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btn_Navigate, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, 215, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(latitude_Lable1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(29, 29, 29)
                                .addComponent(distanceLabel))
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(lbl_Icon, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                .addGap(53, 53, 53))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btn_voice, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
                    .addComponent(btn_Close, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(126, 126, 126)
                        .addComponent(lbl_temperature))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btn_Navigate, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(37, 37, 37)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(latitude_Lable, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(latitude_Lable1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(distanceLabel)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                .addComponent(lbl_Icon, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lbl_temperature1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_humidity)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lbl_description)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_location)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addGap(96, 96, 96)
                .addComponent(btn_voice, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_Close, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXMapKit1, javax.swing.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jXMapKit1, javax.swing.GroupLayout.DEFAULT_SIZE, 764, Short.MAX_VALUE)))
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(GPSMapView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents
    /**
     * this method controls the destination combo box
     * @author Amirhossein Tayarani
     */
    private void btn_NavigateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_NavigateActionPerformed
        // TODO add your handling code here:

        routeDrawer.node.clear();
        routeDrawer.wpSet.clear();
        jXMapKit1.getMainMap().setOverlayPainter(null);
        int i = jComboBox1.getSelectedIndex();
        routeDrawer.setThreadWait(false);
        if(jRadioButton2.isSelected())
            routeDrawer.setWalkOrCar(false);
        else
            routeDrawer.setWalkOrCar(true);
        if (i == 1) {
            routeDrawer.setendPoint(57.704669, 11.937128);
            routeDrawer.dijkstra();
            if(!rdThread.isAlive())
                rdThread.start();
            //                wpPainter.setWaypoints(routeDrawer.wpSet);
            //                wpPainter.setNodes(routeDrawer.node);
            //                jXMapKit1.getMainMap().setOverlayPainter(wpPainter);
            //                jXMapKit1.setZoom(1);
            //                jXMapKit1.repaint();

        } else if (i == 2) {
            routeDrawer.setendPoint(57.70606, 11.936155);
            routeDrawer.dijkstra();
            if(!rdThread.isAlive())
                rdThread.start();
            //                wpPainter.setWaypoints(routeDrawer.wpSet);
            //                wpPainter.setNodes(routeDrawer.node);
            //                jXMapKit1.getMainMap().setOverlayPainter(wpPainter);
            //                jXMapKit1.setZoom(1);
            //                jXMapKit1.repaint();

        } else if (i == 3) {

            routeDrawer.setendPoint(57.70722, 11.939709);
            routeDrawer.dijkstra();
            if(!rdThread.isAlive())
                rdThread.start();
            //                wpPainter.setWaypoints(routeDrawer.wpSet);
            //                wpPainter.setNodes(routeDrawer.node);
            //                jXMapKit1.getMainMap().setOverlayPainter(wpPainter);
            //                jXMapKit1.setZoom(1);
            //                jXMapKit1.repaint();

        } else if (i == 4) {

            routeDrawer.setendPoint(57.706387, 11.938134);
            routeDrawer.dijkstra();
            if(!rdThread.isAlive())
                rdThread.start();
            //                wpPainter.setWaypoints(routeDrawer.wpSet);
            //                wpPainter.setNodes(routeDrawer.node);
            //                jXMapKit1.getMainMap().setOverlayPainter(wpPainter);
            //                jXMapKit1.setZoom(1);
            //                jXMapKit1.repaint();

        } else if (i == 5) {
            routeDrawer.setendPoint(57.705615, 11.936565);
            routeDrawer.dijkstra();
            if(!rdThread.isAlive())
                rdThread.start();
            //                wpPainter.setWaypoints(routeDrawer.wpSet);
            //                wpPainter.setNodes(routeDrawer.node);
            //                jXMapKit1.getMainMap().setOverlayPainter(wpPainter);
            //                jXMapKit1.setZoom(1);
            //                jXMapKit1.repaint();

        } else if (i == 6 && mouseSlector) {
            routeDrawer.dijkstra();
            if(!rdThread.isAlive())
                rdThread.start();
            //                wpPainter.setWaypoints(routeDrawer.wpSet);
            //                wpPainter.setNodes(routeDrawer.node);
            //                jXMapKit1.getMainMap().setOverlayPainter(wpPainter);
            //                jXMapKit1.setZoom(1);
            //                jXMapKit1.repaint();
            mouseSlector = false;

        } else {

            JOptionPane.showMessageDialog(null, "Please select Destination or click by mouse", "ERROR", 1);
        }
//      MP3Player player = new MP3Player("voice//4.mp3");
        

        

    }//GEN-LAST:event_btn_NavigateActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox1ActionPerformed

    private void btn_CloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CloseActionPerformed
        // TODO add your handling code here:
        System.exit(0);
}//GEN-LAST:event_btn_CloseActionPerformed

    private void btn_voiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_voiceActionPerformed
        // TODO add your handling code here:
             if(p.wait){
//                p = new MP3Player("voice//1.mp3");
                p.wait = false;                
             }
    }//GEN-LAST:event_btn_voiceActionPerformed
    /**
     * this method controls the mouse click for destination
     * @author Pooyan Mobtahej
     */
    private void jXMapKit1MouseClicked(MouseEvent evt) {
//          System.exit(0);
        Rectangle rect = jXMapKit1.getMainMap().getViewportBounds();
        int x = evt.getX() + rect.x - 6;
        int y = evt.getY() + rect.y + 13;
        Point clickedPoint = new Point(x, y);
        routeDrawer.setendPoint(jXMapKit1.getMainMap().getTileFactory().pixelToGeo(clickedPoint, jXMapKit1.getMainMap().getZoom()).getLatitude(),
                jXMapKit1.getMainMap().getTileFactory().pixelToGeo(clickedPoint, jXMapKit1.getMainMap().getZoom()).getLongitude());
        mouseSlector = true;
    }
    /** For test only
     * author Mahdi abdinejadi
     */
    @Action
    public void goITUniversity() { // for test only
        //jXMapKit1.setAddressLocation(new GeoPosition(57.706806,11.937413));
        //final RouteDrawer routeDrawer = new RouteDrawer();

//		WaypointPainter wpPainter = new WaypointPainter();
        routeDrawer.dijkstra(57.707541, 11.934843, 57.706406, 11.921968);//test rout
//            routeDrawer.dijkstra(57.424153 ,11.562187, 57.706406, 11.921968);//test rout
//	routeDrawer.dijkstra(57.706675, 11.937268, 57.704669, 11.937128);//IT Uni to Restaurant åran
        //routeDrawer.dijkstra(57.706675, 11.937268, 57.70606, 11.936155);//IT Uni to BackaTheatre
        //routeDrawer.dijkstra(57.706675, 11.937268, 57.70722, 11.939709);//IT Uni to Science Park
        //routeDrawer.dijkstra(57.706675, 11.937268, 57.706387, 11.938134);//IT Uni to Jupiter entrance (facing Patricia)
        //routeDrawer.dijkstra(57.706675, 11.937268, 57.705615, 11.936565);//IT Uni to Ester Mosessons café
        wpPainter.setWaypoints(routeDrawer.wpSet);
        wpPainter.setNodes(routeDrawer.node);
        jXMapKit1.getMainMap().setOverlayPainter(wpPainter);
        jXMapKit1.setZoom(1);
        jXMapKit1.repaint();
        //System.out.println(ml [ml.length-1].toString());
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Close;
    private javax.swing.JButton btn_Navigate;
    private javax.swing.JButton btn_voice;
    private javax.swing.ButtonGroup buttonGroup1;
    public static javax.swing.JLabel distanceLabel;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    public static org.jdesktop.swingx.JXMapKit jXMapKit1;
    private javax.swing.JLabel latitude_Lable;
    private javax.swing.JLabel latitude_Lable1;
    private javax.swing.JLabel lbl_Icon;
    private javax.swing.JLabel lbl_description;
    private javax.swing.JLabel lbl_humidity;
    private javax.swing.JLabel lbl_location;
    private javax.swing.JLabel lbl_temperature;
    private javax.swing.JLabel lbl_temperature1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    // End of variables declaration//GEN-END:variables
//    private final Timer messageTimer;
//    private final Timer busyIconTimer;
//    private final Icon idleIcon;
//    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
    /** the thread which repaint the current location
     * author Navid Ranjbar
     */
    public void run() {
        while(true){
            try {
//                 Thread.sleep(3000);
                jXMapKit1.getMainMap().setOverlayPainter(wpPainter);
//                jXMapKit1.setCenterPosition(routeDrawer.getStartPoint());
//                 jLabel3.setText(Double.toString(routeDrawer.getStartPoint().getLatitude()));
//                 jLabel4.setText(Double.toString(routeDrawer.getStartPoint().getLongitude()));
//                 jLabel3.validate();
//                 jLabel3.setText("");
//         jLabel4.setText("come");
//                jXMapKit1.repaint();
                Thread.sleep(3000);
            } catch (InterruptedException ex) {
                Logger.getLogger(GPSMapView.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

